Mono-Alphabetic Cipher

Module 01 / Lesson 03

Visual Explanation


Beyond Caesar Cipher

In a Mono-Alphabetic Cipher, each letter of the plaintext is replaced by a unique corresponding letter from a randomly shuffled alphabet. Unlike Caesar cipher (which only has 25 possible keys), this method has over 400,000,000,000,000,000,000,000,000 (26!) possible keys.


Key Example:

Plain: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Cipher: Q W E R T Y U I O P A S D F G H J K L Z X C V B N M


Although the number of keys is vast, this cipher is still weak against Frequency Analysis. Since each letter always maps to the same cipher letter, patterns of the language (like the common use of 'E' or 'THE' in English) can be used to break it.


Python Implementation

import string

def mono_alphabetic_cipher(text, key, mode='encrypt'):
    alphabet = string.ascii_uppercase
    key = key.upper()
    
    if mode == 'decrypt':
        # Swap alphabet and key for decryption
        trans_table = str.maketrans(key, alphabet)
    else:
        trans_table = str.maketrans(alphabet, key)
        
    return text.upper().translate(trans_table)

# Key must be 26 unique characters
secret_key = "QWERTYUIOPASDFGHJKLZXCVBNM"
message = "HELLO CIPHERBOY"

encrypted = mono_alphabetic_cipher(message, secret_key)
print(f"Encrypted: {encrypted}") # Output: ITSSG EOHITKRGN